package ca.mcgill.model.digraph;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import ca.mcgill.model.implementation.Task;
import ca.mcgill.model.implementation.Transaction;

public class TransactionDigraph extends Digraph {

	private Transaction transaction;

	private Map<Task, List<TransactionEdge>> taskToOutTrnsEdges = new HashMap<Task, List<TransactionEdge>>();

	public TransactionDigraph(Transaction transaction) {

		this.transaction = transaction;

	}

	public Transaction getTransaction() {
		return this.transaction;
	}

	public Map<Task, List<TransactionEdge>> getTaskToOutTrnsEdges() {
		return taskToOutTrnsEdges;
	}

	public void setTaskToOutTrnsEdges(
			Map<Task, List<TransactionEdge>> taskToOutTrnsEdges) {
		this.taskToOutTrnsEdges = taskToOutTrnsEdges;
	}

	public void addTaskToTrnsEdgeMapping(Task task, TransactionEdge trnsEdge) {

		List<TransactionEdge> edges;

		if ((edges = this.taskToOutTrnsEdges.get(task)) == null) {
			edges = new ArrayList<TransactionEdge>();
			this.taskToOutTrnsEdges.put(task, edges);
		}

		edges.add(trnsEdge);
	}

}
